import yhTools from "@/tools/yh";
import { Toast } from "antd-mobile";
import { InterfaceG } from "@/config/Config";
import store from "@/Redux/Store/Store";

/**获取face++的token */
async function face_getFaceBizToken() {
	Toast.loading("加载中...", 100);
	let objs = {
		url: InterfaceG.face_getFaceBizToken,
		params: { productNo: "802" }
	};
	let resp = await yhTools.request(objs);
	Toast.hide();
	if (resp.code === "0") {
		const token = resp.data.bizToken;
		return token;
	} else {
		Toast.info(resp.message, 2);
		return "";
	}
}

/**
 *
 * 小辉贷人脸逻辑
 */
/**小辉贷人脸 */
const startLive = async props => {
	console.log("场景3。。。");
	let bizToken = "";
	//1.0.6版本替换Face++
	if (yhTools.isHigherVersion()) {
		// 1.0.6版本
		bizToken = await face_getFaceBizToken();
	}
	const url = ["804", "813", "814"].includes(props.currentCode)
		? yhTools.isHigherVersion()
			? InterfaceG.face_authNotSubmitCreditV2
			: InterfaceG.authNotSubmitCredit
		: yhTools.isHigherVersion()
		? InterfaceG.face_authAndSubmitCreditV2
		: InterfaceG.faceAuth;
	const { authHeaderStr } = props.getAppPlatformsDatas;
	let params = {
		needUpload: true,
		url,
		header: authHeaderStr, //头部信息
		bizToken,
		params: {
			channelCode: "YHB",
			productNo: "802",
			bizToken
		},
		_alertShow: false
	};
	yhTools.startLiveFace(params).then(resp => {
		if (resp.status === "1000" && resp.data.code === "0") {
			props.goNext();
		} else {
			Toast.info(resp.data.message, 5);
		}
	});
};

export default {
	startLive
};
